<template>
    <view>
        <view v-if="!isLoad" class="margin-top load loading text-l text-grey"></view>

        <view class="main-admin" v-if="isAdmin && isLoad">
            <view class="form-box shadow">
                <view class="form-group">
                    <view class="title text-cut">{{ title }}</view>
                </view>
            </view>

            <view class="form-box shadow margin-top-xs">
                <view class="checkin">
                    <view class="notice">
                        <text class="icon-scan margin-right-s text-bold"></text>
                        用户自助核销/签到
                    </view>
                    <view class="desc">
                        <text class="text-black text-bold">※ 签到规则</text>
                        <text :user-select="true">
                            1. 预约用户自行扫描下方小程序码完成核销/签到 2. 用户在预约当天扫码有效，不可提前核销 3. 在预约结束时间未到情况下，用户可自行扫码完成核销 4.
                            若结束时间已到，需要管理员进行人工扫码核销或者在后台核销
                        </text>
                    </view>
                    <image @tap="url" data-type="img" :data-url="qrUrl" mode="aspectFill" class="loading" :show-menu-by-longpress="true" :src="qrUrl"></image>
                    <view class="oprt">长按图片保存小程序码</view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
const AdminBiz = require('../../../../biz/admin_biz.js');
const pageHelper = require('../../../../helper/page_helper.js');
const cloudHelper = require('../../../../helper/cloud_helper.js');
export default {
    data() {
        return {
            isLoad: false,
            qrUrl: '',
            title: '',
            isAdmin: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: async function (options) {
        if (!AdminBiz.isAdmin(this)) {
            return;
        }
        if (!pageHelper.getOptions(this, options, 'mark')) {
        }
        if (options && options.title) {
            let title = decodeURIComponent(options.title);
            this.setData({
                title
            });
        }
        await this.loadDetailFun();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: async function () {
        await this.loadDetailFun();
        uni.stopPullDownRefresh();
    },
    methods: {
        loadDetailFun: async function () {
            let timeMark = this.mark;
            let page = pageHelper.fmtURLByPID('/pages/meet/self/meet_self');
            let params = {
                timeMark,
                page
            };
            let opt = {
                title: 'bar'
            };
            try {
                await cloudHelper.callCloudSumbit('admin/self_checkin_qr', params, opt).then((res) => {
                    this.setData({
                        qrUrl: res.data,
                        isLoad: true
                    });
                });
            } catch (err) {
                console.log('CatchClause', err);
                console.log('CatchClause', err);
                console.error(err);
            }
        },

        url: function (e) {
            pageHelper.url(e, this);
        }
    }
};
</script>
<style>
@import './admin_meet_self.css';
</style>
